window._MANAGERJF = {
	
	defatulUserName:'knife',

    _ITEMTYPE:null,

    _HOMENODE:null,

    _GOODSNODE:null,

    _GOODSARR:null,

    _PAGENODE:null,

    _INFONODE:null,

    _CODENODE:null,

    _LANDNODE:null,

    _ISVIP:false,

    _TABARR:['home','prop','equipment','skill','material','teamskill','special'],

    _REALARR:{
        'prop':{'fightItem':null,'senceItem':null,'attrItem':null,'renameItem':null},
        'equipment':{'弓':null,'刀':null,'剑':null,'枪':null,'扇':null,'皮甲':null,'布甲':null,'重甲':null,'坐骑':null},
        'skill':{'火':null,'水':null,'木':null,'金':null,'土':null,'无':null,},
        'material':{'make':null,'stone':null},
        'teamskill':{'arr':null,'arr1':null,'arr2':null},
        'special':{'弓':null,'刀':null,'剑':null,'枪':null,'扇':null,'皮甲':null,'布甲':null,'重甲':null,'坐骑':null}
    },

    _ITEMMAP:{
        'prop':[
                {name:'改名卡*1',price:1000,type:'改名卡',nmb:1},
                {name:'变身器*1',price:1000,type:'变身器',nmb:1},
                {name:'介绍信*10',price:1000,type:'介绍信',nmb:10},
                {name:'大师拘妖符*10',price:1000,type:'大师拘妖符',nmb:10},
                {name:'十香软筋散*10',price:1000,type:'十香软筋散',nmb:10},
                {name:'神级经验丹*10',price:1000,type:'神级经验丹',nmb:10},
                {name:'飞剑*10',price:1000,type:'飞剑',nmb:10},
                {name:'雷火弹*10',price:1000,type:'雷火弹',nmb:10},
                {name:'完美丹*1',price:10000,type:'完美丹',nmb:1},
                {name:'岳飞召唤券*1',price:50000,type:'岳飞召唤券',nmb:1},
                {name:'辛弃疾召唤券*1',price:50000,type:'辛弃疾召唤券',nmb:1},
                {name:'殷叔召唤券*1',price:50000,type:'殷叔召唤券',nmb:1},
        ],
        'equipment':[
            {name:'随机神话弓*1',price:1000,type:'弓',nmb:1},
            {name:'随机神话刀*1',price:1000,type:'刀',nmb:1},
            {name:'随机神话剑*1',price:1000,type:'剑',nmb:1},
            {name:'随机神话枪*1',price:1000,type:'枪',nmb:1},
            {name:'随机神话扇*1',price:1000,type:'扇',nmb:1},
            {name:'随机神话皮甲*1',price:1000,type:'皮甲',nmb:1},
            {name:'随机神话布甲*1',price:1000,type:'布甲',nmb:1},
            {name:'随机神话重甲*1',price:1000,type:'重甲',nmb:1},
            {name:'随机神话坐骑*1',price:1000,type:'坐骑',nmb:1},
            ],
        'skill':[
            {name:'随机火系技能*1',price:1000,type:'火',nmb:1},
            {name:'随机水系技能*1',price:1000,type:'水',nmb:1},
            {name:'随机木系技能*1',price:1000,type:'木',nmb:1},
            {name:'随机金系技能*1',price:1000,type:'金',nmb:1},
            {name:'随机土系技能*1',price:1000,type:'土',nmb:1},
            {name:'随机无属性技能*1',price:1000,type:'无',nmb:1},
        ],
        'material':[
            {name:'随机SS级淬炼材料*10',price:2000,type:'make',nmb:10},
            {name:'随机SS级镶嵌材料*10',price:2000,type:'stone',nmb:10},
        ],
        'teamskill':[
            {name:'急行*1',price:10000,type:'急行',nmb:1},
            {name:'眼力*1',price:10000,type:'眼力',nmb:1},
            {name:'野炊*1',price:10000,type:'野炊',nmb:1},
            {name:'混沌*1',price:10000,type:'混沌',nmb:1},
            //{name:'巧匠*1',price:10000,type:'巧匠',nmb:1},
        ],
        'special':[
            {name:'随机弓制作书*1',price:100,type:'弓',nmb:1},
            {name:'随机刀制作书*1',price:100,type:'刀',nmb:1},
            {name:'随机剑制作书*1',price:100,type:'剑',nmb:1},
            {name:'随机枪制作书*1',price:100,type:'枪',nmb:1},
            {name:'随机扇制作书*1',price:100,type:'扇',nmb:1},
            {name:'随机皮甲制作书*1',price:100,type:'皮甲',nmb:1},
            {name:'随机布甲制作书*1',price:100,type:'布甲',nmb:1},
            {name:'随机重甲制作书*1',price:100,type:'重甲',nmb:1},
            {name:'随机坐骑制作书*1',price:100,type:'坐骑',nmb:1},
            {name:'随机道具制作书*1',price:100,type:'道具',nmb:1},
        ]

    },

    initJf:function(node){

        var maskNode = node.getChildByName('mask');
        var pageNode = node.getChildByName('rightLabel').getChildByName('background').getChildByName('page');
        var pageLeftNode=pageNode.getChildByName('btnLeft');
        var pageRightNode=pageNode.getChildByName('btnRight');
        var tabNode = node.getChildByName('rightLabel').getChildByName('background').getChildByName('tab');
        var homeNode = node.getChildByName('rightLabel').getChildByName('background').getChildByName('home');
        var infoNode = homeNode.getChildByName('info');
        var confirmNode = homeNode.getChildByName('buttonConfirm');
        var landNode = homeNode.getChildByName('buttonLand');
        var adNode = homeNode.getChildByName('buttonTest');
        var codeBox = homeNode.getChildByName('editBox');
        var goodsNode = node.getChildByName('rightLabel').getChildByName('background').getChildByName('goods');
        var goodsNodeArr = goodsNode.getChildren();

        _MANAGERJF._HOMENODE = homeNode;
        _MANAGERJF._GOODSNODE = goodsNode;
        _MANAGERJF._PAGENODE = pageNode;
        _MANAGERJF._INFONODE = infoNode;
        _MANAGERJF._CODENODE = codeBox;
        _MANAGERJF._GOODSARR = goodsNodeArr;
        _MANAGERJF._LANDNODE = landNode;

        maskNode.on(cc.Node.EventType.TOUCH_START,function(){
            this.active = false;
        },
        node);

        //console.log('广告按钮',adNode);
        adNode.on(cc.Node.EventType.TOUCH_START,function(){
            //this.active = false;
            console.log('观看广告');
            if(_HQM._USERNAME){
                _QD.showLbVideo();
            }else{
                _TIPS.showMessage('请先登录',0);
            }
        },
        node);

        landNode.on(cc.Node.EventType.TOUCH_START,function(){
            _QD.loginByQd('jf');
        },
        node);

        confirmNode.on(cc.Node.EventType.TOUCH_START,function(){
            console.log(_MANAGERJF._CODENODE.getComponent(cc.EditBox).string);
            var code = _MANAGERJF._CODENODE.getComponent(cc.EditBox).string;
            if(code)
                _HTTP.buyCode(code);
            else
                _TIPS.showMessage('兑换码不能为空!');
        },
        node);

        pageLeftNode.on(cc.Node.EventType.TOUCH_START,function(){
            console.log('left');
        },
        node);

        pageRightNode.on(cc.Node.EventType.TOUCH_START,function(){
            console.log('right');
        },
        node);

        for(var i=0;i<_MANAGERJF._TABARR.length;i++){
            var temptab = tabNode.getChildByName(_MANAGERJF._TABARR[i]);
            temptab.tabtype = _MANAGERJF._TABARR[i];
            temptab.on(cc.Node.EventType.TOUCH_START,function(){
               console.log(this.tabtype);
               if(this.tabtype=="home"){
                    _MANAGERJF._HOMENODE.active = true;
                    _MANAGERJF._GOODSNODE.active = false;
                    //_MANAGERJF._PAGENODE.active = false;
               }else{
                    _MANAGERJF._HOMENODE.active = false;
                    _MANAGERJF._GOODSNODE.active = true;
                    _MANAGERJF._ITEMTYPE=this.tabtype;
                    _MANAGERJF.refreshGoods();
                    //_MANAGERJF._PAGENODE.active = true;
               }
            },
            temptab);

        }

        for(var i=0;i<goodsNodeArr.length;i++){
            goodsNodeArr[i].goodsIndex = i;
            goodsNodeArr[i].on(cc.Node.EventType.TOUCH_START,function(){
                var arr = _MANAGERJF._ITEMMAP[_MANAGERJF._ITEMTYPE];
                console.log(this.goodsIndex,arr[this.goodsIndex]);
                if(_HQM._USERNAME){
                    if(_MANAGERJF._ISVIP){
                        _MANAGERJF.exchangeByIndexAndType(this.goodsIndex,_MANAGERJF._ITEMTYPE);
                    }else if(_LOCALJF.cutJIFEN(arr[this.goodsIndex].price)){
                        _MANAGERJF.exchangeByIndexAndType(this.goodsIndex,_MANAGERJF._ITEMTYPE);
                        _HTTP.getJf();
                    }else{
                        _HTTP.cutJf(arr[this.goodsIndex].price,this.goodsIndex);
                    }
                }else{
                    _TIPS.showMessage('兑换道具请先登录');
                }
             },
             goodsNodeArr[i]);

        }

        //_MANAGERJF.refreshJFInfo();
        //_HTTP.getJf();

    },

    refreshGoods:function(){

        if(_MANAGERJF._ITEMTYPE&&_MANAGERJF._ITEMMAP[_MANAGERJF._ITEMTYPE]){

            var arr = _MANAGERJF._ITEMMAP[_MANAGERJF._ITEMTYPE];
            for(var i=0;i<_MANAGERJF._GOODSARR.length;i++){
                var node = _MANAGERJF._GOODSARR[i];
                if(arr[i]){
                    node.active = true;
                    _MANAGERJF.refreshGoodNode(node,arr[i]);
                }else{
                    node.active = false;
                }
            }
        }

    },

    refreshGoodNode:function(node,config){

        var name = config.name;
        var price = config.price;
        node.getChildByName('nmb').getComponent(cc.Label).string = price+"积分";
        node.getChildByName('numbei').getComponent(cc.Label).string = name;
        node.getChildByName('img').active = false;

    },

    getRealArrByConfig:function(type,configType){
        if(_MANAGERJF._REALARR[type]){
            if(!_MANAGERJF._REALARR[type][configType]){
                _MANAGERJF._REALARR[type][configType]=[];
                if(type=="teamskill"){
                    /*
                    for(var key in _SKILLTEAM){
                        _MANAGERJF._REALARR[type][configType].push(key);
                    }
                    */
                   /*
                    if(configType=='arr')
                        _MANAGERJF._REALARR[type][configType].push('急行');
                    if(configType=='arr1')
                        _MANAGERJF._REALARR[type][configType].push('眼力');
                    if(configType=='arr2')
                        _MANAGERJF._REALARR[type][configType].push('野营');
                    */
                    _MANAGERJF._REALARR[type][configType].push(configType);

                }else if(type=="material"){
                    for(var key in _M){
                        if(configType=='stone'){
                            if(_M[key].isStone){
                                _MANAGERJF._REALARR[type][configType].push(key);
                            }
                        }else{
                            if(!_M[key].isStone){
                                _MANAGERJF._REALARR[type][configType].push(key);
                            }
                        }
                    }
                }else if(type=="skill"){
                    for(var key in _SKILL){
                        if(
                            //!_SKILL[key].forbidden
                            //_SKILLHEPLER.skillCanRandom(key)
                            //&&(
                            (configType=='无'&&!_SKILL[key].ftype)
                            ||(_SKILL[key].ftype==configType)
                            //)
                        ){
                            _MANAGERJF._REALARR[type][configType].push(key);
                        }
                    }

                    for(var key in _SKILLBD){
                        if(
                            //!_SKILLBD[key].forbidden
                            //_SKILLHEPLER.skillCanRandom(key)
                            //&&(
                            (configType=='无'&&!_SKILLBD[key].ftype)
                            ||(_SKILLBD[key].ftype==configType)
                            //)
                        ){
                            _MANAGERJF._REALARR[type][configType].push(key);
                        }
                    }
                }else if(type=="prop"){

                    for(var i=0;i<_MANAGERJF._ITEMMAP['prop'].length;i++){
                        var mapconfig = _MANAGERJF._ITEMMAP['prop'][i];
                        if(!_MANAGERJF._REALARR[type][mapconfig.type]){
                            _MANAGERJF._REALARR[type][mapconfig.type]=[];
                        }
                        _MANAGERJF._REALARR[type][mapconfig.type].push(mapconfig.type);
                    }

                }else if(type=="equipment"){

                    for(var key in _EQUIP){

                        if(
                            (_EQUIP[key].type==configType)
                            ||(!_EQUIP[key].type&&configType=="坐骑")
                        ){
                            _MANAGERJF._REALARR[type][configType].push(key);
                        }

                    }

                }else if(type=="special"){
                    for(var key in _MAKE){

                        var equip = _MAKE[key].item;
                        if(_EQUIP[equip]){
                            if(
                                (_EQUIP[equip].type==configType)
                                ||(!_EQUIP[equip].type&&configType=="坐骑")
                            ){
                                _MANAGERJF._REALARR[type][configType].push(key);
                            }
                        }else{
                            if(configType=="道具"){
                                _MANAGERJF._REALARR[type][configType].push(key);
                            }
                        }

                    }
                }

            }

            return _MANAGERJF._REALARR[type][configType];
        }
    },

    exchangeByIndexAndType:function(index,type){

        var arr = _MANAGERJF._ITEMMAP[type];
        if(arr&&arr[index]){

            var config = arr[index];
            var nmb = config.nmb;
            var realarr = _MANAGERJF.getRealArrByConfig(type,config.type);
            if(realarr&&realarr.length>0){
                var randomType = _CU.randomObj(realarr);
                for(var i=0;i<nmb;i++){
                    if(!_EQUIP[randomType]){
                        _GAMEDATAHELPER.pushItem(_IOF.createObjByName(randomType,null));
                    }else{
                        var randomParam = {qua:'SS',stone:[]};

                        if(_HDLVHELPER.getHdLv()==2){//噩梦难度掉率纯色装备

                            var tempftype = _CU.randomObj(_MFR.stoneFtype);

                            for(var i=0;i<5;i++){
                                randomParam.stone.push({ftype:tempftype,value:null});
                            }
                            
                        }else{

                            for(var i=0;i<5;i++){
                                randomParam.stone.push({ftype:_CU.randomObj(_MFR.stoneFtype),value:null});
                            }

                        }

                        _GAMEDATAHELPER.pushItem(_IOF.createObjByName(randomType,randomParam));
                    }
                }
            }

            _TIPS.showMessage('兑换成功!获得:'+randomType+"*"+nmb);
        }

    },

    refreshJFInfo:function(isvip,jfnmb){
		
		
		if(isvip){
			_MANAGERJF._ISVIP = true;
		}else{
			_MANAGERJF._ISVIP = false;
		}
		
		if(_MANAGERJF._INFONODE!=null){
			if(isvip){
				_MANAGERJF._INFONODE.getComponent(cc.Label).string = "您已经是VIP了可以无限兑换道具";
			}else{
				var jfstr = "本地积分:"+_LOCALJF.getJIFEN()
				if(jfnmb){
					jfstr += "\n当前剩余服务端积分:"+jfnmb;
				}else{
					jfstr += "\n当前剩余服务端积分:0";
				}
				_MANAGERJF._INFONODE.getComponent(cc.Label).string = jfstr;
			}

			if(_HQM._USERNAME){
				_MANAGERJF._LANDNODE.active=false;
			}else{
				_MANAGERJF._LANDNODE.active=true;
			}
		}
		
		if(window._RANDOM!=null){
			window._RANDOM.refreshJfLabel(null,null);
		}
    }

}